<?php


namespace Yond\LaravelDomain;

use Spatie\DataTransferObject\DataTransferObject as DTO;
use Spatie\DataTransferObject\DataTransferObjectCollection;

class DataTransferObject extends DTO
{
    protected bool $ignoreMissing = true;

    protected function parseArray(array $array): array
    {
        foreach ($array as $key => $value) {
            if (
                $value instanceof DTO
                || $value instanceof DataTransferObjectCollection
            ) {
                $array[$key] = $value->toArray();

                continue;
            }

            if ($value === null) {
                unset($array[$key]);
                continue;
            }

            if (! is_array($value)) {
                continue;
            }

            $array[$key] = $this->parseArray($value);
        }

        return $array;
    }
}